package _88MergeSortedArray;

public class CSolution {

  public static void main(String[] args) {
    System.out.println("aa");
//    merge(new int[] {1, 2, 3, 0, 0, 0}, 3, new int[] {2, 5, 6}, 3);
    merge(new int[] {2, 0}, 1, new int[] {1}, 1);
  }

  private static void merge(int[] nums1, int m, int[] nums2, int n) {
    if (nums2 == null || n == 0) {
      return;
    }
    if (m == 0) {
      for (int i = 0; i < n; i++) {
        nums1[i] = nums2[i];
      }
      return;
    }
    int indexOne = m - 1;
    int indexTwo = n - 1;
    int i = nums1.length - 1;
    int val;
    while (indexOne >= 0 && indexTwo >= 0) {
      if (nums1[indexOne] >= nums2[indexTwo]) {
        val = nums1[indexOne];
        indexOne--;
      } else {
        val = nums2[indexTwo];
        indexTwo--;
      }
      nums1[i] = val;
      i--;
    }
    if (indexTwo >= 0) {
      for (int j = 0; j <= indexTwo; j++) {
        nums1[j] = nums2[j];
      }
    }
  }
}
